//
//  MONumberOfPersonnelOfWaitViewController.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/8/9.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MONumberOfPersonnelOfWaitViewController.h"
#import "MONumberOfPersonnelOfWaitViewCell.h"
#import "MONumberOfPersonnelOfWaitDetailViewController.h"

@interface MONumberOfPersonnelOfWaitViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataSource;

@end

@implementation MONumberOfPersonnelOfWaitViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creatView];
    
    [self initData];
}

-(void)creatView
{
    self.title = @"待办列表";
    
    self.view.backgroundColor = KGrayColor_f8f8f8;
    
    [self.view addSubview:self.tableView];
}

-(void)initData
{
    self.dataSource = [NSMutableArray array];
    NSArray *typeArr = @[@"通知",@"任务",@"测评",@"审批",@"公示",@"收文"];
    NSArray *contentArr = @[@"a关于科级以上人员体检通知",@"全国人大常委会提出推进国有资产管理与监督立法",@"关于数字人事系统学习",@"2019年现实表现测评",@"个人成长账户申诉",@"全国人大常委会提出推进国有资产管理与监督立法"];
    for (int i = 0; i<typeArr.count; i++) {
        MONumberOfPersonnelOfWaitModel *model = [[MONumberOfPersonnelOfWaitModel alloc]init];
        model.typeStr = typeArr[i];
        model.nameStr = contentArr[i];
        model.businessNameStr = @"人员体检";
        model.dateSr = @"2019-09-09";
        if (i==contentArr.count-1) {
            model.readStatus = @"1";
        }
        [self.dataSource addObject:model];
    }
    [self.tableView reloadData];
}

#pragma mark -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MONumberOfPersonnelOfWaitViewCell *cell = [MONumberOfPersonnelOfWaitViewCell cellWithTableView:tableView andIndexPath:indexPath];
    cell.model = self.dataSource[indexPath.row];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [MONumberOfPersonnelOfWaitViewCell heightForMONumberOfPersonnelOfWaitViewCellAndModel:self.dataSource[indexPath.row]];
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0001;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    return nil;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MONumberOfPersonnelOfWaitDetailViewController *vc = [[MONumberOfPersonnelOfWaitDetailViewController alloc]init];
    vc.model = self.dataSource[indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 设置顶头分割线
-(void)viewDidLayoutSubviews {
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])  {
        if (@available(iOS 8.0, *)) {
            [self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
        } else {
            // Fallback on earlier versions
        }
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        if (@available(iOS 8.0, *)) {
            [cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
        } else {
            // Fallback on earlier versions
        }
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
}

#pragma mark -懒加载
-(UITableView *)tableView
{
    if (!_tableView) {
    
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-StatusBarAndNavigationBarHeight) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
//        _tableView.mj_header = [MORefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(downloadAfaterDataSource)];
//        _tableView.mj_footer = [MORefreshGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(downloadBeforeDataSource)];
//        [_tableView.mj_header beginRefreshing];
        
    }
    return _tableView;
}



@end
